package com.example.file_management.pojo.material;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Resource {

    private Integer resourceId;
    private Long taskId;
    private Integer version;
    private String resourceName;
    private String taskName;
    private ResourceType resourceType;
    private String filePath;

    @JsonFormat(pattern = "yyyy.MM.dd HH:mm")
    private LocalDateTime uploadTime;

    private Long size; // 文件大小（字节）

    // 获取前端所需的分类类型
    public String getCategoryType() {
        return switch (this.resourceType) {
            case DOCUMENT, SPREADSHEET -> "document";
            case IMAGE -> "image";
            case VIDEO -> "video";
            default -> "other";
        };
    }

    // 格式化文件大小（GB）
    public String getFormattedSize() {
        if (size == null) return "0.00 GB";
        double gb = size / (1024.0 * 1024 * 1024);
        return String.format("%.2f GB", gb);
    }

    // 格式化更新时间
    public String getFormattedTime() {
        return uploadTime != null
                ? uploadTime.format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm"))
                : "暂无数据";
    }

    public enum ResourceType {
        IMAGE("图像"),
        VIDEO("视频"),
        DOCUMENT("文档"),
        SPREADSHEET("表格"),
        OTHER("其他");

        private final String chineseName;

        ResourceType(String chineseName) {
            this.chineseName = chineseName;
        }

        public String getChineseName() {
            return chineseName;
        }
    }
}
